<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Fly Prod</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" type="text/css" href="default.css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="scripts.js">
        </script>
        <script type="text/javascript">document.onmousemove=move; // dès que la souris bouge, on appelle la fonction move pour mettre à jour la position de la bulle.
        </script>
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    </head>
    <body>
        <div id="upbg"></div>
        <div id="outer">

            <?php
            include 'header.php';
            ?>
            <?php
            include 'login.php';
            include 'menu.php';
            ?>
            <div id="content">
                <?php
                if (isset($_GET['idEvent'])) {
                    $idEvent = $_GET['idEvent'];
                    include_once 'connectBDD.php';
                    $result = mysql_query("SELECT * FROM event WHERE id_event = " . $idEvent);
                    $rows = mysql_fetch_assoc($result);
                    echo "<div class='sousTitreInfoInscription'>" . $rows['name_event'] . "";
                    if (isset($_SESSION['login'])) {
                        $query = "select * from event_user where id_event = '" . $_GET['idEvent'] . "' and login_user = '" . $_SESSION['login'] . "'";
                        $result = mysql_query($query) or die(mysql_error());
                        if (mysql_num_rows($result) > 0) {
                            echo "<span id='participer'><a style='color:red' href=\"javascript:participerEvenement('" . $_GET['idEvent'] . "' , 'participe plus')\" />Je ne viens plus</a></span>";
                        } else {
                            echo "<span id='participer' ><a style='color:green' href=\"javascript:participerEvenement('" . $_GET['idEvent'] . "', 'participe')\" />Je viens ! </a></span>";
                        }
                    }
                    echo" </div>";
                    ?>
                    <div id="likeFacebook">
                        <!-- Plugin facebook // Marchera si un jour on a un nom de domaine-->
                        <iframe
                            src="https://www.facebook.com/plugins/like.php?href=https://www.facebook.com/tyga"
                            scrolling="no"
                            frameborder="0"
                            style="border:none; width:100%; height:80px"></iframe>
                    </div>
                    <div id="contenuGauche">

                        <?php
                        $flyer_path = $rows['flyer_path'];
                        //Informations
                        echo "
                        
                        <div id='sousContenuGauche'>
                            <div id='sousTitre'>Informations générales</div>
                            <div class='detailEvent'>
                                <div><span>Adresse</span> : " . $rows['address_event'] . "</div>
                                <div><span>Ville</span> : " . $rows['city_event'] . "</div>
                                <div><span>Date</span> : " . date_format(new DateTime($rows['date_event']), 'd/m/Y') . "</div>
                                <div><span>Prix sur place</span> : " . $rows['price_normal'] . "€ / <span>Prix prévente</span> : " . $rows['price_presale'] . "€</div>
                                <div><span>Description</span> :<div id='descEvent'><p>" . stripslashes($rows['description_event']) . "</p></div></div><br/>
                            </div>";


                        //Liste des commentaires
                        echo "
                            <div id='sousTitre'>Commentaires</div>
                            <div class='sousTitreInfo'>";
                        if (isset($_SESSION['login'])) {
                            echo"</div>
                            <div id='formComment'>
                                <form action='' method=\"post\">
                                    <input type='hidden' value='$idEvent' id='id_event'>
                                    <textarea name='comment' id='inputComment'  rows='10' cols='45'></textarea><br/>
                                    <input type='submit' value='enregistrer' name='bouton'/>
                                </form>
                                <span class='error' id='error_5' style='display:none'>Saisissez un commentaire !</span>
                                <span class='success' id='success_5' style='display:none'>Commentaire ajouté</span>
                            </div>
                        ";
                        } else {
                            echo"<span id='modifierInfo'>
                            <p>Vous devez vous connecter pour pouvoir commenter.</p>
                            <a id='modifComment' href='creationCompte.php'>S'inscrire</a>
                        </span></div>";
                        }

                        echo "</div> "; //fin sousContenuGauche
                        echo"<div class='flyerEventDetail'>
                                <img src='" . $flyer_path . "' width=300px height=400px/>
                              </div>";

                        echo "<div id='blocCom'>";
                        $query = "SELECT c.id_comment, c.comment, c.login, c.dateTime, u.avatar_path FROM comments c, user u WHERE c.login = u.login and c.id_event = $idEvent ORDER BY c.dateTime desc";
                        $result3 = mysql_query($query);
                        if (!$result3) {
                            echo mysql_error();
                        }
                        $nb_res = mysql_num_rows($result3);
                        if ($nb_res > 0) {



                            while ($rows = mysql_fetch_assoc($result3)) {
                                echo"
                         <div class='commentaire'>
                            <div id='petite_image'>
                                <img src=" . $rows['avatar_path'] . " width='50px' height='50px' />
                            </div>";
                                if (isset($_SESSION['login']) && $_SESSION['login'] == $rows['login']) {
                                    echo "<a class='croix_ferm' href=\"javascript:supprimerCommentaire('" . $rows['id_comment'] . "', $idEvent, 'utilisateur')\"><img src='images/picto_croix.gif'/></a>";
                                }
                                echo"<div id='blockLoginMP'>
                                <div id='login_msg'>
                                    <a href='profil.php?login=" . $rows['login'] . "'>" . $rows['login'] . "</a>
                                     <span class='heure_msg'>" . date_format(new DateTime($rows['dateTime']), 'd/m/Y à H:i:s') . "</span>
                                </div>
                                
                            </div><br style='clear:both'/>
                            <div id='comment_content'><p>" . $rows['comment'] . "</p></div>
                        </div>";


                                /* echo "<div class='commentaire'>
                                  Par <a href='ficheUser.php?login=" . $rows['login'] . "'>" . $rows['login'] . "</a> le " .
                                  date_format(new DateTime($rows['dateTime']), 'd/m/Y à H:i:s') . "<br/>" . $rows['comment'] .
                                  "</div>"; */
                            }
                        } else {
                            echo "<br/><p id='firstCom'>Soyez donc le premier à commenter cet évènement !</p>";
                        }
                        echo "</div>";
                        ?>


                    </div>
                    <div id="contenuDroit">
                        <?php
                        //DJ partipant a l'évènement
                        //On récupère les pseudos des DJ associé a l'event
                        $result2 = mysql_query("SELECT D.id_dj, D.pseudo_dj FROM dj D INNER JOIN event_dj ED ON D.id_dj = ED.id_dj where ED.id_event = " . $idEvent);
                        if (!$result2) {
                            echo mysql_error();
                        }
                        echo "<h3>DJ présents</h3>";
                        while ($rows = mysql_fetch_assoc($result2)) {
                            echo "<div>" . $rows['pseudo_dj'] . "</div>";
                        }
                        //Adhérents participants à l'évènement
                        echo "<br/><br/><h3>Participants</h3>";
                        //On récupère les avatar des adhérents associés à l'event
                        $result4 = mysql_query("SELECT U.avatar_path,U.login FROM user U INNER JOIN event_user EU ON U.login = EU.login_user where EU.id_event = " . $idEvent);
                        if (!$result4) {
                            echo mysql_error();
                        }
                        echo "<div id='participants'>";
                        $i = 0;
                        $nb = 1;
                        while ($rows = mysql_fetch_assoc($result4)) {
                            if ($i % 4 == 0) {
                                echo "<div>";
                            }
                            $i++;
                            echo "<div class='userEvent' onmouseover=montre('" . $rows['login'] . "') onmouseout=cache()>
                                <a href='profil.php?login=" . $rows['login'] . "'>
                                    <img src=" . $rows['avatar_path'] . " alt=" . $rows['login'] . " width=50px height=50px'/>
                                </a>
                              </div>";
                            if ($i == 4 || $nb == mysql_num_rows($result4)) {
                                echo '</div>';
                                $i = 0;
                            }
                            $nb++;
                        }
                        echo "</div>";
                        ?>
                        <div id="curseur" class="infobulle">
                        </div>

                        <?php
                    } else {
                        echo "Cet évènement n'existe pas.";
                    }
                    ?>
                </div>
            </div>
            <?php
            include 'footer.php';
            ?>
        </div>
    </body>
</html>

